package com.whnk.model.controller;

import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.mysql.cj.xdevapi.JsonArray;
import com.whnk.common.core.web.controller.BaseController;
import com.whnk.common.core.web.domain.AjaxResult;
import com.whnk.model.service.IDatIndexInfoService;
import com.whnk.model.vo.DatIndexInfoStatus;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Tong
 * @create 2021-9-7 14:38
 */
@RestController
@RequestMapping("/indexInfo")
public class DatIndexInfoController extends BaseController {

    @Autowired
    private IDatIndexInfoService datIndexInfoService;
    //注解拦截器
//    @PreAuthorize(hasPermi = "model:indexInfo:list")
    @GetMapping(value = "/{logo}")
    public AjaxResult list(@PathVariable("logo") String logo)
    {
        List<DatIndexInfoStatus>  list = null;
        String[] name =null;
        String[] value=null;
        switch (logo){
            //交易笔数
            case "openAccounts":
                list =datIndexInfoService.accountsOpenedCount();
                name =new String[list.size()];
                value=new String[list.size()];
                for (int i = 0; i <list.size() ; i++) {
                    name[i] = list.get(i).getTimeString();
                    //去掉小数点及三位
                    value[i] =list.get(i).getIndexValue().substring(0,list.get(i).getIndexValue().length()-5);
                }
                break;
             //当月交易金额按机构排行top10
            case "amountTop":
                list =datIndexInfoService.amountMonthCount();
                name =new String[list.size()];
                value=new String[list.size()];
                for (int i = 0; i <list.size() ; i++) {
                    name[i] = list.get(i).getBrName();
                    value[i] =list.get(i).getIndexValue();
                }
                break;
             //按机构和时间(昨天)统计贷款余额
            case "loanBalance":
                list =datIndexInfoService.loanBalanceCount();
                name =new String[list.size()];
                value=new String[list.size()];
                for (int i = 0; i <list.size() ; i++) {
                    name[i] = list.get(i).getBrName();
                    value[i] =list.get(i).getIndexValue();
                }
                break;
             //统计当月开户数，交易金额，贷款余额
            case "sameMonth":
                list =datIndexInfoService.sameMonthCount();
                name =new String[list.size()];
                value=new String[list.size()];
                for (int i = 0; i <list.size() ; i++) {
                    name[i] = list.get(i).getIndexName();
                    value[i] =list.get(i).getIndexValue();
                }
                break;
             //按机构和时间(昨天)统计交易金额
            case "transAmount":
                list =datIndexInfoService.transactionAmountCount();
                name =new String[list.size()];
                value=new String[list.size()];
                for (int i = 0; i <list.size() ; i++) {
                    name[i] = list.get(i).getBrName();
                    value[i] =list.get(i).getIndexValue();
                }
                break;
            default: list = new ArrayList<DatIndexInfoStatus>();
                name =new String[0];
                value=new String[0];
        }


        Map map = new HashMap();
        map.put("name",name);
        map.put("value",value);
        return AjaxResult.success(map);
    }

    @ApiOperation(value = "根据指标编号查询相关统计")
    @GetMapping(value = "/{indexCode}")
    public AjaxResult list2(String[] indexCode)
    {
        List<DatIndexInfoStatus>  list = null;
        String[] name =null;
        String[] value=null;
        list =datIndexInfoService.selectIndexCodes(indexCode);
        name =new String[list.size()];
        value=new String[list.size()];
        for (int i = 0; i <list.size() ; i++) {
            name[i] = list.get(i).getIndexName();
            value[i] =list.get(i).getIndexValue();
        }
        Map map = new HashMap();
        map.put("name",name);
        map.put("value",value);
        return AjaxResult.success(map);
    }

}
